package array;

// 977.有序数组的平方
// https://leetcode.cn/problems/squares-of-a-sorted-array/
public class SortedSquares {
    public int[] sortedSquares(int[] nums) {
        int[] newArr = new int[nums.length];
        int index = nums.length - 1;
        int i = 0;
        int j = nums.length - 1;
        while ( i <= j) {
            if (nums[i]* nums[i] >= nums[j] * nums[j]) {
                newArr[index] = nums[i] * nums[i];
                i ++;
            } else {
                newArr[index] = nums[j] * nums[j];
                j --;
            }
            index -- ;

        }
        return newArr;
    }
}
// -4,-1,0,3,10
// 0,1,9,16,100
